package com.itedge.solutionmanager.domain.impl;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Version;
import javax.validation.constraints.Size;

import com.itedge.infrastructure.domain.IEntity;
import com.itedge.infrastructure.domain.IProcessEntity;
import com.itedge.solutionmanager.enumeration.CustomerStatus;

@Entity
@Table(name="CUSTOMER")
public class Customer implements IEntity, IProcessEntity {
	
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Long id;	

	@Version
    @Column(name = "version")
    private Integer version;

    @Column(name="PROCESS_ID")
    private String processInstanceId; 	

	@Column(name ="DESCRIPTION")
	@Size(max = 4000)
	private String description;

	@OneToMany(cascade = CascadeType.ALL)
    @JoinTable(name="CUSTOMERS_CONTACTS",
            joinColumns=@JoinColumn(name="CUSTOMER_ID"),
            inverseJoinColumns=@JoinColumn(name="CONTACT_ID")
        )
    private Set<ContactPerson> contactPersons = new HashSet<ContactPerson>();
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "customer")
    private Set<Solution> solutions = new HashSet<Solution>();

	@Embedded
    private Address address;  
	
	@Column(name ="NAME")
	@Size(max = 255)
	private String name;	
	
	@Column(name ="ICO")
	@Size(max = 255)
	private String ico;
	
	@Column(name ="DIC")
	@Size(max = 255)
	private String dic;
	
	@Column(name ="ICDPH")
	@Size(max = 255)
	private String icdph;
    
    @Enumerated(EnumType.ORDINAL)
    @Column(name="STATUS")
    private CustomerStatus status;	
    
	public CustomerStatus getStatus() {
		return status;
	}

	public void setStatus(CustomerStatus status) {
		this.status = status;
	}

	@Override
	public String getProcessInstanceId() {
		return processInstanceId;
	}

	@Override
	public void setProcessInstanceId(String processInstanceId) {
		this.processInstanceId = processInstanceId;
	}	
	
    public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getIco() {
		return ico;
	}

	public void setIco(String ico) {
		this.ico = ico;
	}

	public String getDic() {
		return dic;
	}

	public void setDic(String dic) {
		this.dic = dic;
	}

	public String getIcdph() {
		return icdph;
	}

	public void setIcdph(String icdph) {
		this.icdph = icdph;
	}

	public Set<Solution> getSolutions() {
		return solutions;
	}

	public void setSolutions(Set<Solution> solutions) {
		this.solutions = solutions;
	}   
    
	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	public Set<ContactPerson> getContactPersons() {
		return contactPersons;
	}

	public void setContactPersons(Set<ContactPerson> contactPersons) {
		this.contactPersons = contactPersons;
	}
	
	public void addContactPerson(ContactPerson person) {
		this.contactPersons.add(person);
	}
	
	public void removeContactPersons(Set<ContactPerson> contactPersons) {
		this.contactPersons.removeAll(contactPersons);
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Override
	public Long getId() {
        return this.id;
    }

	public void setId(Long id) {
        this.id = id;
    }	

	@Override
	public Integer getVersion() {
        return this.version;
    }

	public void setVersion(Integer version) {
        this.version = version;
    }
}